/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.kj.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.kj.entity.KjMember;
import com.jeesite.modules.sys.entity.Office;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.alibaba.fastjson.JSONValidator;
import com.jeesite.common.codec.EncodeUtils;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.kj.entity.KjSkill;
import com.jeesite.modules.kj.service.KjSkillService;

/**
 * kj_skillController
 * @author hzy
 * @version 2021-07-06
 */
@Controller
@RequestMapping(value = "${adminPath}/kj/kjSkill")
public class KjSkillController extends BaseController {

	@Autowired
	private KjSkillService kjSkillService;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public KjSkill get(String id, boolean isNewRecord) {
		return kjSkillService.get(id, isNewRecord);
	}

	/**
	 * 查询列表
	 */
	@RequiresPermissions("kj:kjSkill:view")
	@RequestMapping(value = {"list", ""})
	public String list(KjSkill kjSkill, Model model) {
		model.addAttribute("kjSkill", kjSkill);
		return "modules/kj/kjSkillList";
	}

	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("kj:kjSkill:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<KjSkill> listData(KjSkill kjSkill, HttpServletRequest request, HttpServletResponse response) {
		kjSkill.setPage(new Page<>(request, response));
		Page<KjSkill> page = kjSkillService.findPage(kjSkill);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("kj:kjSkill:view")
	@RequestMapping(value = "form")
	public String form(KjSkill kjSkill, Model model) {
		model.addAttribute("kjSkill", kjSkill);
		return "modules/kj/kjSkillForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("kj:kjSkill:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated KjSkill kjSkill) {
		kjSkillService.save(kjSkill);
		return renderResult(Global.TRUE, text("保存特长成功！"));
	}

	/**
	 * 删除数据
	 */
	@RequiresPermissions("kj:kjSkill:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(KjSkill kjSkill) {
		kjSkillService.delete(kjSkill);
		return renderResult(Global.TRUE, text("删除特长成功！"));
	}

	/**
	 * 列表选择对话框
	 */
	@RequiresPermissions("kj:kjSkill:view")
	@RequestMapping(value = "kjSkillSelect")
	public String empUserSelect(KjSkill kjSkill, String selectData, Model model) {
		String selectDataJson = EncodeUtils.decodeUrl(selectData);
		if (selectDataJson != null && JSONValidator.from(selectDataJson).validate()){
			model.addAttribute("selectData", selectDataJson);
		}
		model.addAttribute("KjSkill", kjSkill);
		return "modules/kj/kjSkillSelect";
	}


	@RequiresPermissions("sys:kjSkill:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(KjSkill skill) {
		skill.setStatus(Office.STATUS_DISABLE);
		kjSkillService.updateStatus(skill);
		return renderResult(Global.TRUE, text("停用成功"));
	}

	@RequiresPermissions("sys:kjSkill:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(KjSkill skill) {
		skill.setStatus(Office.STATUS_NORMAL);
		kjSkillService.updateStatus(skill);
		return renderResult(Global.TRUE, text("启用成功"));
	}

}
